/* Copyright (c) 2004-2024 Peigen.info. All rights reserved. */

package info.peigen.hotpot.component.feedback.service.processor.create;

import cn.hutool.core.lang.Assert;
import info.peigen.hotpot.common.core.result.ResultCode;
import info.peigen.hotpot.common.service.base.exception.BusinessException;
import info.peigen.hotpot.common.service.base.processor.Processor;
import info.peigen.hotpot.common.service.base.processor.ProcessorServiceContext;
import info.peigen.hotpot.component.feedback.domain.Feedback;
import info.peigen.hotpot.component.feedback.result.FeedbackCreateResult;
import info.peigen.hotpot.component.feedback.service.processor.AbstractFeedbackServiceProcessor;
import info.peigen.hotpot.component.feedback.util.FeedbackManageConvertor;
import org.noear.solon.annotation.Component;

/**
 * <b>(FeedbackCreateResultProcessor)</b>
 *
 * @author Peigen
 * @version 1.0.0
 * @since 2023/1/6
 */
@Component
public class FeedbackCreateResultProcessor extends AbstractFeedbackServiceProcessor implements Processor {
    @Override
    public Integer level() {
        return 91;
    }

    @Override
    public void execute(ProcessorServiceContext serviceContext) {
        Feedback domain = (Feedback) serviceContext.getDomain();
        Assert.notNull(domain, () -> new BusinessException(ResultCode.FAILURE, "Feedback不得为空[order=" + serviceContext.getOrder() + "]"));
        FeedbackCreateResult result = (FeedbackCreateResult) serviceContext.getResult();
        result.fromSuccess(FeedbackManageConvertor.convertToInfo(domain));
    }
}